package com.whfc.iot;

import com.whfc.iot.server.IotServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: 环境监测仪socket服务器(HJ - 2017)
 * @author: xugcheng
 * @version: 1.0
 * @date: 2021-01-27 11:20
 */
@SpringBootApplication(scanBasePackages = "com.whfc")
@EnableAsync
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class IotHjApplication implements CommandLineRunner {

    public static int HJ_PORT = 8150;
    public static int DUST_PORT = 8140;
    public static int GAS_PORT = 8141;

    @Resource(name = "hjServer")
    private IotServer hjServer;

    @Resource(name = "dustServer")
    private IotServer dustServer;

    @Resource(name = "gasServer")
    private IotServer gasServer;

    public static void main(String[] args) {
        SpringApplication.run(IotHjApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        ExecutorService executorService = Executors.newFixedThreadPool(3);
        executorService.execute(() -> {
            hjServer.port(HJ_PORT);
            hjServer.run();
        });
        executorService.execute(() -> {
            dustServer.port(DUST_PORT);
            dustServer.run();
        });
        executorService.execute(() -> {
            gasServer.port(GAS_PORT);
            gasServer.run();
        });
    }
}
